db = [["admin","123456",1],["lizhuolin","123456",0]]
finance = [
    ["id","类别","账户","金额","时间","说明"],
    [1,"吃饭支出","交通银行",147.8,"2024-03-12","家庭聚餐"],
    [2,"工资收入","现金",4500.0,"2024-03-15","发工资了"],
    [3,"服装支出","现金",450.0,"2024-03-16","买衣服"],
    [4,"股票支出","工商银行",1000.66,"2024-04-18","股票大涨，买买买"],
]
attempt = 0
while attempt < 3:
    username = input("请输入用户名: ")
    password = input("请输入密码: ")
    for user in db:
        if user[0] == username and user[1] == password:
            user_type = user[2]
            print("登陆成功！")
            break
    else:
        print("用户名或密码错误，请重试。")
        attempt += 1
        continue
    break
else:
    print("三次尝试失败，程序退出。")
    exit()

if user_type == 1:
    while True:
        print("管理员您好，请选择您的操作。")
        print("1.添加账务 2.编辑账务 3.删除账务 4.复杂查询 5.退出系统")
        admin_choice = input("请选择操作: ")
        if admin_choice == "1":
            new_id = max(record[0] for record in finance[1:])+1
            category = input("请输入类别（如工资、投资收益等）: ")
            account = input("请输入账户（如银行卡、公积金账户等）: ")
            amount = float(input("请输入金额: "))
            date = input("请输入日期: ")
            note = input("请输入备注信息: ")
            new_record = [category, account,amount,date,note]
            finance.append(new_record)
            print("新的财务事件创建成功！")
        elif admin_choice == "2":
            record_id = int(input("请输入要编辑记录的索引: "))
            for record in finance[1:]:
                if record[0] == record_id:
                    category = input("请输入新的类别: ")
                    account = input("请输入新的账户: ")
                    amount = float(input("请输入新的金额: "))
                    date = input("请输入新的日期: ")
                    note = input("请输入新的备注信息: ")
                    record[1] = category
                    record[2] = account
                    record[3] = amount
                    record[4] = date
                    record[5] = note
                    print("修改成功")
                    break
            else:
                print("未找到对应的账务ID。")
        elif admin_choice == "3":
            record_id = int(input("请输入要删除记录的索引: "))
            for index, record in enumerate(finance[1:]):
                if record[0] == record_id:
                    confirm = input("您确定要删除这条财务记录吗？这可是不可逆的操作哦！（Y/N）").lower()
                    if confirm == 'y':
                        del finance[index+1]
                        print("记录已成功删除，您的管理空间更加清爽。")
                        print(finance)
                    else:
                        print("删除操作已取消。")
                    break
            else:
                print("未找到对应的账务ID。")

        elif admin_choice == "4":
            query_type = input("请选择查询条件（特定时间（D）/特定金额范围（A））: ").lower()
            if query_type == 'd':
                start_date = input("请输入开始日期: ")
                end_date = input("请输入结束日期: ")
                print(f"查询结果:")
                found = False
                for record in finance[1:]:
                    if start_date <= record[4] <= end_date:
                        print(record)
                        found = True
                if not found:
                    print("未找到符合条件的记录。")
            elif query_type == 'a':
                min_amount = float(input("请输入最小金额: "))
                max_amount = float(input("请输入最大金额: "))
                print(f"查询结果:")
                found = False
                for record in finance[1:]:
                    if min_amount <= record[3] <= max_amount:
                        print(record)
                        found = True
                if not found:
                    print("未找到符合条件的记录。")
            else:
                print("无效的查询条件。")

        elif admin_choice == "5":
            print("退出系统")
            break
        else:
            print("无效选择，请重试。")

else:
    while True:
        print("用户您好：1.查询所有 2.按条件查询")
        choice = input("请选择操作: ")
        if choice == "1":
            for record in finance[1:]:
                print(record)

        elif choice == "2":
            category = input("请输入类别: ")
            for record in finance[1:]:
                if record[1] == category:
                    print(record)
        else:
            print("无效选择，请重试。")
            continue
        another_choice = input("是否继续操作（y/n）: ")
        if another_choice.lower()!= "y":
            break